﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AIC_Notification
{
    class TeacherStatusForLT: StatisticsReport
    {
        public TeacherStatusForLT()
        {
            ReportTitle = "Teacher Status (Leadership)";
        }

        public override string GetSubject()
        {
            return String.Format("{0} - {1:d}", ReportTitle, Global.Now());
        }

        public override string EmptyInnerTable()
        {
            return "<tr><td style=\"padding: 10px 0 10px 0; text-align:center;\">No Issue Found</td></tr>";
        }

        public override string GenerateInnerTable()
        {
            string tableBody = "";

            tableBody += "<tr style=\"background-color: #483D8B; color: white;\">";
            tableBody += "<th style=\"font-size: 14px; width: 16%;\">Consultant</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">SOF Student Count</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Avg. School in Rally</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Draft Assigned</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Overdue Drafts</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Revisions Pending</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Overdue Revisions</th>";
            // tableBody += "<th style=\"font-size: 14px;\">Progress Score</th>";
            tableBody += "</tr>";

            var SortedTeachers = TeacherDB.Teachers.OrderBy(Teacher => Teacher.Name);
            foreach (var Teacher in SortedTeachers)
            {
                if ((Teacher.Type == "Academic Consultant" || Teacher.Type == "Both") &&
                    (Teacher.ApplicationStats.ProgressScore > 0))
                {
                    if ((Teacher.Name == "Chen Zhang" || Teacher.Name == "Johnny Lee" || Teacher.Name == "Pei Yen" || Teacher.Name == "Xin Shi"))
                        continue;

                    tableBody += "<tr>";
                    tableBody += String.Format("<td style=\"font-size: 14px;\"><b>{0}</b></td>", Teacher.Name);
                    tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", Teacher.ApplicationStats.TotalStudents);
                    tableBody += String.Format("<td style=\"font-size: 14px;\">{0:0.00}</td>", Teacher.ApplicationStats.AverageSchoolInRally);
                    if (Teacher.ApplicationStats.TotalAssignedDraft == 0)
                        tableBody += String.Format("<td style=\"font-size: 14px; background-color: #FFFFCC\">{0}</td>", Teacher.ApplicationStats.TotalAssignedDraft);
                    else
                        tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", Teacher.ApplicationStats.TotalAssignedDraft);
                    tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", Teacher.ApplicationStats.TotalOverDuedDraft);
                    tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", Teacher.ApplicationStats.TotalPendingRevision);
                    if (Teacher.ApplicationStats.TotalOverDuedRevision > 0)
                        tableBody += String.Format("<td style=\"font-size: 14px; background-color: #F8D3D3;\">{0}</td>", Teacher.ApplicationStats.TotalOverDuedRevision);
                    else
                        tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", Teacher.ApplicationStats.TotalOverDuedRevision);
                    // tableBody += String.Format("<td style=\"font-size: 14px;\">{0:0.0000}</td>", Teacher.ApplicationStats.ProgressScore);
                    tableBody += "</tr>";
                }
            }

            tableBody += "<tr style=\"background-color: #483D8B; color: white;\">";
            tableBody += "<th style=\"font-size: 14px; width: 16%;\">City</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">SOF Student Count</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Avg. School in Rally</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Draft Assigned</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Overdue Drafts</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Revisions Pending</th>";
            tableBody += "<th style=\"font-size: 14px; width: 14%;\">Overdue Revisions</th>";
            // tableBody += "<th style=\"font-size: 14px;\">Progress Score</th>";
            tableBody += "</tr>";

            foreach (var City in CityDB.Cities)
            {
                tableBody += "<tr>";
                tableBody += String.Format("<td style=\"font-size: 14px;\"><b>{0}</b></td>", CityDB.GetCityName((CityDB.CityEnum)City.CityNumber));
                tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", City.ApplicationStats.TotalStudents);
                tableBody += String.Format("<td style=\"font-size: 14px;\">{0:0.00}</td>", City.ApplicationStats.AverageSchoolInRally);
                if (City.ApplicationStats.TotalAssignedDraft == 0)
                    tableBody += String.Format("<td style=\"font-size: 14px; background-color: #FFFFCC\">{0}</td>", City.ApplicationStats.TotalAssignedDraft);
                else
                    tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", City.ApplicationStats.TotalAssignedDraft);
                tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", City.ApplicationStats.TotalOverDuedDraft);
                tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", City.ApplicationStats.TotalPendingRevision);
                if (City.ApplicationStats.TotalOverDuedRevision > 0)
                    tableBody += String.Format("<td style=\"font-size: 14px; background-color: #F8D3D3;\">{0}</td>", City.ApplicationStats.TotalOverDuedRevision);
                else
                    tableBody += String.Format("<td style=\"font-size: 14px;\">{0}</td>", City.ApplicationStats.TotalOverDuedRevision);
                // tableBody += String.Format("<td style=\"font-size: 14px;\">{0:0.0000}</td>", City.ApplicationStats.ProgressScore);
                tableBody += "</tr>";
            }

            return tableBody;
        }

        public override void SendReportAsEmail()
        {
            string HTMLBody;

            FileName = String.Format("{0}-{1:yyyyMMdd-HHmmss}.htm", ReportTitle, Global.Now());
            Global.SysUtil.Log("Generating Report: " + FileName);

            HTMLBody = GetHTMLBody();

            if (!IsEmptyBody) // only send e-mail or generate content if any
            {
                // Save Report to File
                SaveReportToFile(FileName, HTMLBody);

                // Send Report E-mail
                toRecipients.Clear();
                ccRecipients.Clear();

                toRecipients.Add("aic-lt@jq-edu.com");
                toRecipients.Add("wai.cheng@jq-edu.com");
                SubjectID = "";

                Global.SysUtil.SendHTML(toRecipients, ccRecipients, GetSubject(), HTMLBody);
            }
        }
    }
}
